package com.java110.mall.shop.cmd.shopType;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.mall.shop.bmo.shopType.ISaveShopTypeBMO;
import com.java110.po.shop.ShopTypePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "shopType.saveShopType")
public class SaveShopTypeCmd extends Cmd {

    @Autowired
    private ISaveShopTypeBMO saveShopTypeBMOImpl;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "typeName", "请求报文中未包含typeName");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        ShopTypePo shopTypePo = BeanConvertUtil.covertBean(reqJson, ShopTypePo.class);
        ResponseEntity<String> responseEntity = saveShopTypeBMOImpl.save(shopTypePo);
        cmdDataFlowContext.setResponseEntity(responseEntity);
    }
}
